from django.core.management.base import BaseCommand
from core.models import Category

class Command(BaseCommand):
    help = '列出所有分类'

    def handle(self, *args, **options):
        def print_category(category, level=0):
            prefix = '  ' * level
            self.stdout.write(f'{prefix}{category.id}. {category.title} (slug: {category.slug})')
            for child in Category.objects.filter(parent=category).order_by('order_index'):
                print_category(child, level + 1)

        # 从根分类开始打印
        root = Category.objects.get(parent=None)
        print_category(root) 